#include "util.h"
#include <stdio.h>
#include <time.h>

char* GetStartDate()
{
    time_t now;
    struct tm* ts;
    time(&now);
    ts = localtime(&now);
    char *date = new char[64];
    sprintf(date, "%d/%d/%d %d:%d:%d", 1900+ts->tm_year, 1+ts->tm_mon, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);
    return date;
}

void LOG_DEBUG(string func, string msg)
{
    FILE* fp;
    if ((fp = fopen("demo.log", "at")) == NULL)
        return;
    fprintf(fp, "[LOG_DEBUG]%s %s: %s\n", GetStartDate(), func.c_str(), msg.c_str());
    fclose(fp);
}

void printAddMemberSucc(string memName, int mid)
{
    cout << "OK. " << memName << "'s id is " << mid << endl;
}

void printAddCardSucc(string cardType, int cardNum, string memName)
{
    cout << "OK. A new " << cardType << " with " << cardNum << " times added to " << memName << endl;
}

void print_error(string msg)
{
    cout << msg << endl;
}
